﻿// cmdAddCylinderCommand.cpp
//

#include "stdafx.h"


////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
//
// BEGIN AddCylinderCommand command
//

#pragma region AddCylinderCommand command

class CCommandAddCylinderCommand : public CRhinoCommand
{
public:
	CCommandAddCylinderCommand() = default;
	UUID CommandUUID() override
	{
		// {dabf2ce8-37c8-4722-afd4-e90d08037681}
		static const GUID AddCylinderCommandCommand_UUID =
		{0xdabf2ce8,0x37c8,0x4722,{0xaf,0xd4,0xe9,0x0d,0x08,0x03,0x76,0x81}};
		return AddCylinderCommandCommand_UUID;
	}
	const wchar_t* EnglishCommandName() override { return L"AddCylinder"; }
	CRhinoCommand::result RunCommand(const CRhinoCommandContext& context) override;
};

// The one and only CCommandAddCylinderCommand object
static class CCommandAddCylinderCommand theAddCylinderCommandCommand;

CRhinoCommand::result CCommandAddCylinderCommand::RunCommand(const CRhinoCommandContext& context)
{
	ON_3dPoint center_point(0.0, 0.0, 0.0);
	double radius = 5.0;
	ON_3dPoint height_point(0.0, 0.0, 10.0);
	ON_3dVector zaxis = height_point - center_point;
	ON_Plane plane(center_point, zaxis);
	ON_Circle circle(plane, radius);
	ON_Cylinder cylinder(circle, zaxis.Length());
	ON_Brep* brep = ON_BrepCylinder(cylinder, TRUE, TRUE);
	if (brep)
	{
		CRhinoBrepObject* cylinder_object = new CRhinoBrepObject();
		cylinder_object->SetBrep(brep);
		if (context.m_doc.AddObject(cylinder_object))
			context.m_doc.Redraw();
		else
			delete cylinder_object;
	}

	return CRhinoCommand::success;
}

#pragma endregion

//
// END AddCylinderCommand command
//
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
